package com.study.news.controls;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.study.news.dao.CommentDao;
import com.study.news.pojo.Comment;

/**
 * Servlet implementation class CommentServlet
 */
@WebServlet("/CommentServlet")
public class CommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CommentServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		int newsid = Integer.valueOf(request.getParameter("newsid"));
		String content = request.getParameter("content");
		String author = request.getParameter("author");
		System.out.println(content);
		CommentDao commentDao = new CommentDao();
		System.out.println("�����������ͬѧ");
		System.out.println("我是唐宇豪");
		commentDao.addComment(new Comment(newsid, content, author));
		response.sendRedirect("http://localhost:8080/TR1803/new?id=" + newsid);
	}

}
